<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="创建时间" prop="gmtTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.gmtTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="业务类型" prop="relType">
        <el-select v-model="queryParams.relType" placeholder="请选择业务类型" clearable size="small">
          <el-option
            v-for="dict in relTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="账单类型" prop="billType">
        <el-select v-model="queryParams.billType" placeholder="请选择账单类型" clearable size="small">
          <el-option
            v-for="dict in billTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="billList" >

      <el-table-column label="账单类型" align="center" prop="billType" width="160" :formatter="billTypeFormat"/>
      <el-table-column label="业务类型" align="center" prop="relType" width="160" :formatter="relTypeFormat"/>
      <el-table-column label="账单金额" align="center" prop="amount" width="160"/>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="创建时间" align="center" prop="gmtTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gmtTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listBill } from "@/api/agent/bill";

export default {
  name: "Bill",
  props: {
    agentId: {
      type: Number,
      default: undefined
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 服务商账单 表格数据
      billList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        relType: undefined,
        billType: undefined,
        agentId: this.agentId,
      },
      billTypeOptions:[],
      relTypeOptions:[],
    };
  },
  created() {
    this.getList();
    this.getDicts("bill_type").then(response => {
      this.billTypeOptions = response.data;
    });
    this.getDicts("agent_bill_reltype").then(response => {
      this.relTypeOptions = response.data;
    });
  },
  methods: {
    /** 查询服务商账单 列表 */
    getList() {
      this.loading = true;
      listBill(this.queryParams).then(response => {
        this.billList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    billTypeFormat(row, column) {
      return this.selectDictLabel(this.billTypeOptions, row.billType);
    },
    relTypeFormat(row, column) {
      return this.selectDictLabel(this.relTypeOptions, row.relType);
    },
  }
};
</script>
